<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 * $Id: 2017-12-13 03:39:35 apple $
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$return=array();
if($_RQ['op']=='list'){
	//搜索
	$params=array('uniacid'=>$_SESSION['uniacid'],'pid'=>0);
	if($_RQ['title']){
		$params['title like']='%'.trim($_RQ['title']).'%';
		$return['params']['title']=$_RQ['title'];
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = 15;
	$total='';
	$list=pdo_getslice('jy_onlineedu_video_group',$params,array($pindex,$psize),$total,$fields,'','paixu desc,id desc');
	if($list){
		foreach($list as &$row){
		}
	}
	$return['list']=$list?$list:array();
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>array(
			'0'=>array('op'=>'list','title'=>'课程分类列表'),
		),
		'list'=>array('data'=>'list','delall'=>false,'list'=>array(
			array('name'=>'paixu','title'=>'排序','type'=>'string'),
			array('name'=>'title','title'=>'名称','type'=>'string'),
			array('name'=>'thumb','title'=>'logo','type'=>'image'),
		),'action'=>array(
			array('type'=>'href','action'=>'jy_onlineedu/video_group/zilist/','title'=>'子菜单'),
		)
		),
		'search_one'=>array('name'=>'name','add_op'=>'edit')
	);
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='zilist'){
	//搜索
	$pid=intval($_RQ['id']);
	if($pid){
		$this->session('pid',$pid);
	}else{
		$pid=$this->session('pid');
	}
	$params=array('uniacid'=>$_SESSION['uniacid'],'pid'=>$pid);
	if($_RQ['title']){
		$params['title like']='%'.trim($_RQ['title']).'%';
		$return['params']['title']=$_RQ['title'];
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = 15;
	$total='';
	$list=pdo_getslice('jy_onlineedu_video_group',$params,array($pindex,$psize),$total,$fields,'','paixu desc,id desc');
	if($list){
		foreach($list as &$row){
		}
	}
	$return['list']=$list?$list:array();
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>array(
			array('op'=>'zilist','title'=>'子分类列表'),
			array('op'=>'ziedit','title'=>'添加子分类'),
		),
		'list'=>array('data'=>'list','delall'=>false,'list'=>array(
			array('name'=>'paixu','title'=>'排序','type'=>'string'),
			array('name'=>'title','title'=>'名称','type'=>'string'),
			array('name'=>'thumb','title'=>'logo','type'=>'image'),
		)
		),
		'search_one'=>array('name'=>'name','add_op'=>'ziedit')
	);
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='edit'){
	$id=intval($_RQ['id']);
	if($id){
		$item=pdo_get('jy_onlineedu_video_group',array('uniacid'=>$_SESSION['uniacid'],'id'=>$id));
	}else{
		$item=array();
	}
	$return['item']=$item;
	$htmls=array(
		'type'=>'edit',
		'post'=>'post',
		'desc'=>'课程分类详情',
		'tabs'=>array(
			array('op'=>'list','title'=>'课程分类列表'),
		),
		'edit'=>array(
			array('type'=>'string','title'=>'名称','name'=>'title', 'help'=>'' ),
			array('type'=>'image','title'=>'logo','name'=>'thumb', 'help'=>'' ),
			array('type'=>'switch','title'=>'是否显示','name'=>'status','help'=>'' ),
			array('type'=>'string','title'=>'排序','name'=>'paixu' , 'help'=>''),
		)
	);
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='ziedit'){
	$id=intval($_RQ['id']);
	if($id){
		$item=pdo_get('jy_onlineedu_video_group',array('uniacid'=>$_SESSION['uniacid'],'id'=>$id));
	}else{
		$item=array();
	}
	$return['item']=$item;
	$htmls=array(
		'type'=>'edit',
		'post'=>'zipost',
		'desc'=>'课程分类详情',
		'tabs'=>array(
			array('op'=>'zilist','title'=>'课程分类列表'),
		),
		'edit'=>array(
			array('type'=>'string','title'=>'名称','name'=>'title', 'help'=>'' ),
			array('type'=>'image','title'=>'logo','name'=>'thumb', 'help'=>'' ),
			array('type'=>'switch','title'=>'是否显示','name'=>'status','help'=>'' ),
			array('type'=>'string','title'=>'排序','name'=>'paixu' , 'help'=>''),
		)
	);
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='post'){
	$post=get_postdata();
	$data=array(
		'title'=>trim($post['title']),
		'thumb'=>trim($post['thumb']),
		'status'=>intval($post['status']),
		'paixu'=>intval($post['paixu']),
	);
	$id=intval($post['id']);
	if($id){
		pdo_update('jy_onlineedu_video_group',$data,array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
	}else{
		$data['uniacid']=$_SESSION['uniacid'];
		pdo_insert('jy_onlineedu_video_group',$data);
	}
	exi('保存成功！','','list');
}
if($_RQ['op']=='zipost'){
	$post=get_postdata();
	$data=array(
		'title'=>trim($post['title']),
		'thumb'=>trim($post['thumb']),
		'status'=>intval($post['status']),
		'pid'=>$this->session('pid'),
		'paixu'=>intval($post['paixu']),
	);
	$id=intval($post['id']);
	if($id){
		pdo_update('jy_onlineedu_video_group',$data,array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
	}else{
		$data['uniacid']=$_SESSION['uniacid'];
		pdo_insert('jy_onlineedu_video_group',$data);
	}
	exi('保存成功！','','zilist');
}
if($_RQ['op']=='del'){
	$del=trim($_RQ['del'],';');
	if($del){
		$del=explode(';',$del);
	}else{
		$del=array();
	}
	if($_RQ['id']){
		$del[]=$_RQ['id'];
	}
	foreach($del as $id){
		$id=intval($id);
		if($id){
			pdo_delete('jy_onlineedu_video_group',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
		}
	}
	exi('删除成功！');
}
?>